﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<div class="gridPanel" style="height:100%;">
    <div id="toolbar" style="padding:2px 5px;">
        <div class="dcui-btn-area">
            <a href="#" id="NF-details" authorize="yes" class="dcui-btn dcui-btn-purple" onclick="btn_details()"><i class="fa fa-eye"></i>查看用户</a>
            <a href="#" id="NF-update" authorize="yes" class="dcui-btn dcui-btn-orange" onclick="btn_updateUser()"><i class="fa fa-reply"></i>更新数据</a>
        </div>
        @*<script>$('#toolbar').authorizeButton()</script>*@
        <div class="dcui-search-area">
            关键字: <input class="easyui-textbox" style="width:110px" id="txt_keyword" placeholder="请输入要查询关键字">
            <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="btn_search">查询</a>
        </div>
    </div>

    <table id="dg" class="easyui-datagrid" style="width:100%;min-height:600px;height:100%;"></table>
</div>

<script>
    $(function () {
        gridList();
    })
    function gridList() {

        $('#dg').datagrid({
            url: "/WeixinManage/WxUsers/GetGridJson",
            toolbar: '#toolbar',
            autoRowHeight: false,
            nowrap: true,
            singleSelect: true,
            method: 'get',
            columns: [[
                { field: 'uuId', hidden: true },
                { field: 'Nickname', title: '用户', width: 120, align: 'center' },
                {
                    field: 'HeadImgUrl', title: '头像', width: 80, align: 'right',
                    formatter: function (value, row, index) {
                        return value == "" ? "" : "<img src=\"" + cellvalue + "\" style='width: 60px;'></img>";
                    }
                },
                {
                    field: 'Sex', title: '性别', width: 60, align: 'right',
                    formatter: function (value, row, index) {
                        return value == 1 ? "开启" : "关闭";
                    }
                },
                { field: 'Mobile', title: '手机', width: 120, align: 'center' },
                { field: 'Province', title: '省份', width: 120, align: 'center' },
                { field: 'City', title: '城市', width: 120, align: 'center' },
                 { field: 'SubscribeTime', title: '关注时间', width: 120, align: 'center' },
                {
                    field: 'Status', title: '状态', width: 60, align: 'right',
                    formatter: function (value, row, index) {
                        return value == "0" ? "废除" : "可用";
                    }
                },
                { field: 'CreateDate', title: '创建时间', width: 120, align: 'right' },
                { field: 'UpdateDate', title: '更新时间', width: 120, align: 'right' }
            ]]
        });

        $("#btn_search").click(function () {
            var queryJson = {
                keyword: $("#txt_keyword").val()
            }
            $('#dg').datagrid('load', queryJson);
        });
    }

    function btn_details() {
        var selected = $('#dg').datagrid('getSelected');
        if (selected != null) {
            $.modalOpen({
                id: "Details",
                title: "查看微信用户",
                url: "/WeixinManage/WxUsers/Details?keyValue=" + selected.uuId,
                width: "450px",
                height: "500px",
                btn: null,
            });
        }
        else {
            $.modalMsg("未选中数据", "warning");
        }
    }
    function btn_updateUser() {
        $.submitPost({
            title: "确定要更新微信用户吗？",
            url: "/WeixinManage/WxUsers/GetWeixinUser",
            success: function () {
                $('#dg').datagrid('reload');
            }
        })
    }
    function btn_updateGroup() {
        $.submitPost({
            title: "确定要更新分组信息吗？",
            url: "/WeixinManage/WxUsers/GetDepartment",
            success: function () {
                $('#dg').datagrid('reload');
            }
        })
    }
    function btn_sendMsg() {
        $.submitPost({
            url: "/WeixinManage/WxUsers/SendWrokMsg",
            param: { keyValue: $("#gridList").jqGridRowValue().Userid },
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }

</script>
